import java.util.Arrays;

public class MyStack implements InStack{
    public int[] elem;
    public int usedsize;
    public static final int Fixd_Capacity = 5;
    public MyStack(){
        this.elem = new int[Fixd_Capacity];
    }
    @Override//入栈
    public void push(int val) {
        if(isFull()) {
            elem = Arrays.copyOf(elem,2*elem.length);//扩容两倍
        }
        elem[usedsize] = val;
        usedsize++;
    }

    @Override
    public int pop() {
        if(isEmpty()){
            throw new EmptyException("栈为空...");
        }
        int val = elem[usedsize-1];
        usedsize--;
        return val;
    }
    @Override
    public int peep() {
        if (isEmpty()) {
            throw new EmptyException("栈为空...");
        }
        return elem[usedsize-1];
    }

    @Override
    public boolean isEmpty() {
        return usedsize == 0;
    }

    @Override
    public boolean isFull() {
       return usedsize == elem.length;
    }
    //打印栈
    public void disPlay() {
        for (int i = 0; i < usedsize; i++) {
            System.out.print(elem[i] + " ");
        }
        System.out.println();
    }
}
